package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.ProductUnit;
import com.spzx.product.service.IProductUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品单位 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-12-20
 */
@Tag(name = "商品单位管理")
@RestController
@RequestMapping("/productUnit")
public class ProductUnitController extends BaseController {
    @Autowired
    private IProductUnitService productUnitService;

    @Operation(summary = "获取分页列表")
    @GetMapping("/list")
    public TableDataInfo findPage(@Parameter(description = "商品单位名称") String name)
    {
        startPage();
        List<ProductUnit> list = productUnitService.selectProductUnitList(name);
        return getDataTable(list);
    }

    @Operation(summary = "根据id获取单位详情信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(
            @Parameter(description = "单位id")
            @PathVariable Long id){
        return success(productUnitService.getById(id));
    }

    @Operation(summary = "新增单位")
    @PostMapping
    public AjaxResult add(
            @Parameter(description = "新增单位对象信息")
            @RequestBody ProductUnit productUnit){
        return toAjax(productUnitService.save(productUnit));
    }
    @Operation(summary = "修改单位信息")
    @PutMapping
    public AjaxResult edit(
            @Parameter(description = "修改单位对象信息")
            @RequestBody ProductUnit productUnit
    ){
        return toAjax(productUnitService.updateById(productUnit));
    }
    @Operation(summary = "根据id集合删除单位")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(description = "单位id集合",example = "[1,2]")
            @PathVariable List<Long> ids){
        return toAjax(productUnitService.removeByIds(ids));
    }
    @Operation(summary = "获取全部单位")
    @GetMapping("/getUnitAll")
    public AjaxResult selectProductUnitAll(){
        return success(productUnitService.list());

    }
}
